package com.song.JavaThread_day04.ch4_2;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class Server {
	
	
	private ThreadPoolExecutor executor;

	public Server() {
		super();
		executor = (ThreadPoolExecutor)Executors.newCachedThreadPool();
	}
	
	public void executeTask(Task task)
	{
		System.out.printf(" server : a new task has arrived  \n");
		executor.execute(task);
		System.out.printf(" server : pool size is %d  \n" ,executor.getPoolSize());
		System.out.printf(" server : active Count is %d  \n" ,executor.getActiveCount());
		System.out.printf(" server : Completed tasks %d  \n",executor.getCompletedTaskCount());
		
	}
	
	public void endServer()
	{
		executor.shutdown();
	}
}
